package com.aricksm.xuan.activaty02;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ExpandableListActivity extends AppCompatActivity {

    ExpandableListView expandableListView;

    String[] groupStringArr = {"腾讯", "百度", "阿里爸爸"};
    String[][] childStrignArrs = {
            {"QQ","微信","QQ浏览器"},
            {"百度搜索", "百度地图","百度外卖"},
            {"淘宝", "支付宝", "天猫商城"}
    };

    List<Map<String, ?>> groupData = new ArrayList<>();
    List<List<Map<String, ?>>> childData = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        expandableListView = (ExpandableListView) findViewById(R.id.demo_expandable_list_view);

        for (int i = 0; i < groupStringArr.length; i++) {
            Map<String, String> map = new HashMap<>();
            map.put("groupName", groupStringArr[i]);

            groupData.add(map);

            List<Map<String, ?>> itemList = new ArrayList<>();
            for (int j = 0; j < childStrignArrs[i].length; j++) {
                Map<String, String> map0 = new HashMap<>();
                map0.put("itemName", childStrignArrs[i][j]);
                itemList.add(map0);
            }
            childData.add(itemList);
        }


        SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(this, groupData,
                R.layout.expandable_list_item_group, new String[]{"groupName"}, new int[]{R.id.tv_group},
                childData, R.layout.expandable_list_item_child, new String[]{"itemName"}, new int[]{R.id.tv_child});

        expandableListView.setAdapter(adapter);

    }


}
